package com.yin.spring5.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * AccountDaoImpl
 *
 * @author Yin Guiqing
 */
@Repository
public class AccountDaoImpl implements AccountDao {
    final JdbcTemplate jdbcTemplate;

    @Autowired
    public AccountDaoImpl(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public void addMoney(int id, int money) {
        String sql = "UPDATE account SET balance=balance+? WHERE id=?";
        jdbcTemplate.update(sql, money, id);
    }

    @Override
    public void deductMoney(int id, int money) {
        String sql = "UPDATE account SET balance=balance-? WHERE id=?";
        jdbcTemplate.update(sql, money, id);
    }
}
